//
//  GoodsListView.swift
//  Aiwei
//
//  Created by zhu xietong on 2017/11/12.
//  Copyright © 2017年 zhu xietong. All rights reserved.
//

import Foundation
import Eelay
import soapp


open class GoodsItemView: RuleCell {
    public let imgV = UIImageView()
    public let titleL = UILabel()
    public let tagsL = UILabel()
    public let priceL = UILabel()
    public let numL = UILabel()
    open override func addLayoutRules() {
        contentView.eelay = [
            [imgV,[ee.T.L.B,[0,0,0]],"50",50],
            [titleL,[imgV,ee.R,ee.L,8],[imgV,ee.T,4],[ee.R,-100]],
            [tagsL,[imgV,ee.R,ee.L,8],[imgV,ee.B,-4],[ee.R,-100]],
            [priceL,[ee.R],[titleL,ee.Y]],
            [numL,[ee.R],[tagsL,ee.Y]],
//            [__line,[ee.L.B.R,[0,0.0]],"0.5"]
        ]
//        __line.backgroundColor = FieldCell.separator_color
        
        imgV.img_url = __goods.one_str
        titleL.ui.font12.cl_222.text(__goodsNames.one_str)
        tagsL.ui.font12.cl_999.text("颜色：黑")
        priceL.ui.font12.cl_222.right.text("¥ 120")
        numL.ui.font12.cl_999.right.text("X1")
    }
    open override func mo_model_reload() {
        imgV.img_url = mo.model["thumb",""]
        titleL.text = mo.model["goods_title",""]
        tagsL.text = mo.model["spec_key_name",""]
        priceL.text = "¥ " + mo.model[float:"real_price",0].price_display
        numL.text = "X " + mo.model["total","1"]
        
        
        
    }
}

open class GoodsListView<Kit:RuleCell>: JoView {
    public let listV = RuleView<Kit>()
    public weak var controller:UIViewController? = nil
    open override func addLayoutRules() {
        eelay = [
            [listV,[ee.T.B,[0,-0]],[ee.X]],
        ]
        listV.space = (0,10)
        listV.limit_width = Swidth - 2*AppTheme.edge
        listV.padding = [0,0,0,0]
        listV.que_num = 1
        listV.item_height = 50
        
        weak var wself = self
        listV.touchAction = { _,_,data in
            Goods.seeDetail(obj: data, at: wself?.controller)
           
        }
    }
    
    open override func mo_model_reload() {
        listV.mo.model = mo.model
    }    
}
